package com.sgb.knowledgeshare.utils;

import android.app.Activity;
import android.content.Context;

import androidx.annotation.NonNull;

import com.github.dfqin.grantor.PermissionListener;
import com.github.dfqin.grantor.PermissionsUtil;
import com.sgb.knowledgeshare.view.activity.HomeShareActivity;

/**
 * 知识分享权限效验
 */
public class SharePermissionUtils {
    public static final String[] BASIC_EXTERNAL_STORAGE = new String[]{
            android.Manifest.permission.CAMERA,
            android.Manifest.permission.RECORD_AUDIO,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
            android.Manifest.permission.READ_EXTERNAL_STORAGE
    };
    public static void getPermission(Activity activity) {
        if (PermissionsUtil.hasPermission(activity, BASIC_EXTERNAL_STORAGE)) {
            HomeShareActivity.start(activity);
        } else {
            PermissionsUtil.requestPermission(activity, new PermissionListener() {
                @Override
                public void permissionGranted(@NonNull String[] permissions) {
                    HomeShareActivity.start(activity);
                }
                @Override
                public void permissionDenied(@NonNull String[] permissions) {
                }
            }, BASIC_EXTERNAL_STORAGE);
        }
    }
    public static void getPermissionTwo(Activity activity,int i) {
        if (PermissionsUtil.hasPermission(activity, BASIC_EXTERNAL_STORAGE)) {
            HomeShareActivity.start(activity);
        } else {
            PermissionsUtil.requestPermission(activity, new PermissionListener() {
                @Override
                public void permissionGranted(@NonNull String[] permissions) {
                    HomeShareActivity.start(activity,i);
                }
                @Override
                public void permissionDenied(@NonNull String[] permissions) {
                }
            }, BASIC_EXTERNAL_STORAGE);
        }
    }
}
